<?php
	session_start();
	if(isset($_SESSION['quid'])&&$_SESSION['quid']=="start"&&isset($_SESSION['thisevent'])){//管理员登录了thisevent这次事件
		$thisevent=$_SESSION['thisevent'];
		$code = mt_rand(100000,999999); 
		$freshtime=time();
		//创建连接
		$conn = mysqli_connect("localhost", "root", "", "signin");
		mysqli_query($conn,"set names utf8");
		//检测连接
		if (!$conn){
			die("Connection failed:".mysqli_connect_error());
		}
		$code = mysqli_real_escape_string($conn,$code);
		$freshtime = mysqli_real_escape_string($conn,$freshtime);
		$sql1 = "SELECT * FROM persons WHERE event='$thisevent' AND username='start'";
		$result1 = mysqli_query($conn, $sql1);
		if($row = mysqli_fetch_assoc($result1)){//如果已经存在
			$sql2="update persons set add_time='$freshtime' where event='$thisevent' AND username='start'";
			$result = mysqli_query($conn,$sql2);//处理数据库
			$sql21="update persons set code='$code' where event='$thisevent' AND username='start'";
			$result = mysqli_query($conn,$sql21);//处理数据库
		}else{
			echo "000001";
			exit();
		}
		echo $code;
		exit();
	}else{
		echo "000000";
		exit();
	}
?>